<?php
/**
 * Created by PhpStorm.
 * User: haobin
 * Date: 2016/10/29
 * Time: 10:47
 * 发布视频 codecotain的值为2,3
 */
require('../conn.php');
require('../functions.php');
require('../QueryList.class.php');
require('admin.php');
if ($_POST) {
    $url = $_POST['long'];
    $codeV = $_POST['code'];
    $codeArr = explode("#",$codeV);
    $code = $codeArr[0];
    $code_content = $codeArr[1];
    $html =get_contentsM($url);
    $reg = [
        'title' => ['p:first', 'text'],
        'video' => ['.video_player', 'html'],
        'pic' => ['.vid_img', 'html'],
    ];
    $hj = QueryList::Query($html, $reg);
    $arr = $hj->jsonArr;
    //获取video的src
    $videoStr = $arr[0]['video'];
    $str = 'yx=&amp;refer=weibo_app" preload="preload">';
    $replaceStr = cut($videoStr, "?", '""');
    $content = str_replace($replaceStr, $str, $videoStr);
    $video = cut($content, "src=\"", "\"");
    //判断是否已有这个视频
    $res = $mysql->query("select id from `news` WHERE `video_url`='{$video}'");
    if($res){
        echo "<script>alert('请勿重复添加')</script>";
        echo "<script>location.href='./addVideo.php'</script>";
        exit;
    }
//获取缩略图
    $picDiv = $arr[0]['pic'];
    $pic = cut($picDiv, 'data-url="', '"');
//获取标题
    $title = $arr[0]['title'];
    //插入news表
    $videoData = [
        'content' => $title,
        'video_url' => $video,
        'img' => $pic,
        'flag' => 4,
        'type' => 1,
        'code' => $code,
        'code_content' => $code_content,
    ];
    $res = $mysql->query("insert into `news`".arr2s($videoData));
    $insertID = mysql_insert_id();
    if($insertID){
        echo "<script>location.href='./editVideo.php?id={$insertID}'</script>";
    }else{
        echo "<script>alert('导入失败！');</script>";
        echo "<script>location.href='./addVideo.php'</script>";
    }
} ?>
<?php include('head.php') ?>
<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span9">
            <h1 class="page-title">发布视频</h1>

            <div class="well">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#home" data-toggle="tab">发布</a></li>
                    <li><a href="http://www.kan25.com/new.html" target="_blank">更多视频</a></li>
                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form id="tab" action="" method="post">
                            <label>标签</label>
                            <select name="code">
                                <?php
                                $row_code = $mysql->query("select code,title from `codetype` where `containvideo`=2 or `containvideo`=3");
                                foreach ($row_code as $row):
                                ?>
                                <option value="<?= $row['code'] ?>#<?=$row['title']?>"><?= $row['title'] ?></option>
                                <?php endforeach;?>
                            </select>
                            <label>秒拍视频网址：</label>
                            <input type="text" value="" style="width:500px" name="long"><br/>

                            <p>例如：<code>http://m.miaopai.com/show/channel/kHiL5IxgQNCNxfxBYRzXJQ__</code>
                            </p>

                            <p>备注：<code>请筛选秒拍视频，并用浏览器切换成手机模式复制网址</code>
                            </p>
                            <label></label>
                            <button class="btn btn-primary"><i class="icon-save"></i> 提交</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="lib/bootstrap/js/bootstrap.js"></script>
</body>
</html>